﻿<%@ taglib uri="/mytaglib" prefix="ct"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/includes.jsp"%>
<script>
	$(document).ready(function() {
		
		$(".datetimepicker").datetimepicker({
			language:"zh-CN",
			format: 'yyyy-mm-dd hh:ii:ss',
			todayBtn:"linked",
			todayHighlight:"true",
			autoclose:"true"
        });
		
		$(":checkbox,button").click(function(event){
			event.stopPropagation();//阻止冒泡事件，上级的单击事件不会被调用
			}); 
		$(":checkbox").parent().click(function(event){
			event.stopPropagation();//阻止冒泡事件，上级的单击事件不会被调用
			}); 
	});
	
	function changeCheck(id){
		$("#"+id).click();
	}
	
	function showConsoleLogDetail(id){
		myAjaxSumbmit('', '/consoleLog/ajax/entity?id=' + id, '', function(
				data) {

			document.getElementById("editConsoleLogForm").reset();
			myValidate.resetForm();
			$('#id').val(id);
			$('#operatorId').val(data.operatorId);
			$('#operatorName').val(data.operatorName);
			$('#logType').val(data.logType);
			$('#createdAt').val(data.createdAt);
			$('#content').val(data.content);
			$('#operateTime').val(data.operateTime);
			$('#operateMethod').val(data.operateMethod);

			$("#editConsoleLogModalLabel").text("查看");
			$("#editSaveConsoleLogBtn").hide();
			$('#editConsoleLogModal').removeClass("modal-warning");
			$('#editConsoleLogModal').addClass("modal-info");
			$(".has-error").removeClass('has-error');
			
			$('#editConsoleLogModal').modal('show');

		});
	}
	
	function toggleAll(){
		$(":checkbox").prop("checked",$("#allClickTag").is(':checked'));
	}
	
	var form = $("#editConsoleLogForm");
	var myValidate = form
	.validate({
		showErrors : function(errorMap, errorList) {
			for (var i = 0; i < errorList.length; i++) {
				$(errorList[i].element).parent().parent().addClass(
						'has-error');
			}
			this.defaultShowErrors();
		},
		success : function(label, element) {
			$(element).parent().parent().removeClass('has-error');
		}
	});
	
	function toConsoleLogAdd(){

		document.getElementById("editConsoleLogForm").reset();
		myValidate.resetForm();
		$(".has-error").removeClass('has-error');

		$("#editConsoleLogModalLabel").text("新增");
		$("#editSaveConsoleLogBtn").show();
		$("#editSaveConsoleLogBtn").attr("onclick", "saveConsoleLogAdd()");
		$('#editConsoleLogModal').removeClass("modal-warning");
		$('#editConsoleLogModal').removeClass("modal-info");
		
		$('#editConsoleLogModal').modal('show');
	}	
	
	function saveConsoleLogAdd(){

		if (form.valid()) {
			myAjaxSumbmit('editConsoleLogForm',
					'/consoleLog/ajax/save',
					'/consoleLog/list', function() {
						$('#editConsoleLogModal').modal('hide');
					});
		}
	}
	
	function toConsoleLogModify(id){
		myAjaxSumbmit('', '/consoleLog/ajax/entity?id=' + id, '', function(
				data) {

			document.getElementById("editConsoleLogForm").reset();
			myValidate.resetForm();
			$('#id').val(id);
			$('#operatorId').val(data.operatorId);			
			$('#operatorName').val(data.operatorName);			
			$('#logType').val(data.logType);			
			$('#createdAt').val(data.createdAt);			
			$('#content').val(data.content);			
			$('#operateTime').val(data.operateTime);			
			$('#operateMethod').val(data.operateMethod);			
			
			$("#editConsoleLogModalLabel").text("修改");
			$('#editConsoleLogModal').addClass("modal-warning");
			$('#editConsoleLogModal').removeClass("modal-info");
			$("#editSaveConsoleLogBtn").attr("onclick", "modifyConsoleLog(" + id + ")");
			$("#editSaveConsoleLogBtn").show();
			$(".has-error").removeClass('has-error');
			$('#editConsoleLogModal').modal('show');

		});
	}
	
	function modifyConsoleLog(id) {
		if (!(id === undefined) && id != '') {
			if (form.valid()) {
				myAjaxSumbmit('editConsoleLogForm',
						'/consoleLog/ajax/update',
						'/consoleLog/list', function() {
							$('#editConsoleLogModal').modal('hide');
						});
			}
		} else {
			alert("请选择修改项！");
		}
	}
	
	function delConsoleLogConfirm(id) {
		$("#delConfirmContent").html("确认删除这个日志？");
		$("#delConfirmButton").attr("onclick", "delConsoleLog(" + id + ")");
		$('#delModal').modal('show');
	}
	
	function delConsoleLog(id) {
		if (!(id === undefined) && id != '') {
			myAjaxSumbmit('noData',
					'/consoleLog/ajax/del?id=' + id, '/consoleLog/list',
					function() {
						$('#delModal').modal('hide');
					});
		} else {
			alert("请选择删除项！");
		}
	}
	
	function delConsoleLogs(ids) {
			myAjaxSumbmit('consoleLogListForm',
					'/consoleLog/ajax/delAll', '/consoleLog/list',
					function() {
						$('#delModal').modal('hide');
					});		
	}
	
	function delAllConsoleLogConfirm(){
		var len=$(":checkbox[name=ids]:checked").length;
		if(len>0){
			$("#delConfirmContent").html("确认删除这些日志？");
			$("#delConfirmButton").attr("onclick", "delConsoleLogs()");
			$('#delModal').modal('show');
		}else{
			alert("请选择删除项！");
		}
	}
	
	function searchConsoleLog(){
		mySubmit('searchConsoleLogForm', '/consoleLog/list');
	}
</script>



<div class="box-header">
<form id="searchConsoleLogForm">
	<div class="col-sm-2">
		<h3 class="box-title">日志管理列表</h3>
	</div>
	<div class="col-sm-2">
		<input type="text" name="operatorId" class="form-control input-sm pull-right" placeholder="操作人id" value="${searchConsoleLogPagingVo.operatorId }">
	</div>
	<div class="col-sm-2">
		<input type="text" name="operatorName" class="form-control input-sm pull-right" placeholder="操作人" value="${searchConsoleLogPagingVo.operatorName}">
	</div>
	<div class="col-sm-2">
		<div class="input-group">
			<input type="text" name="logType" class="form-control input-sm pull-right" placeholder="日志类型" value="${searchConsoleLogPagingVo.logType}">
			<div class="input-group-btn">
				<button type="button" class="btn btn-sm btn-default" onclick="searchConsoleLog()">
					<i class="fa fa-search"></i>
				</button>
			</div>
		</div>
	</div>
	</form>
	<div class="box-tools">
		<button type="button" onclick="delAllConsoleLogConfirm()" class="btn btn-danger btn-flat">批量删除</button>
		<button type="button" onclick="toConsoleLogAdd()" class="btn btn-primary btn-flat">新增</button>
	</div>


</div>
<!-- /.box-header -->
<div class="box-body table-responsive no-padding">

	<form id="consoleLogListForm">
		<table class="table table-hover  table-bordered">
			<tbody>
				<tr>
					<th width="5%" onclick="changeCheck('allClickTag')">全选<input type="checkbox" onchange="toggleAll()" id="allClickTag"></th>
					<th >操作人id</th>
					<th >操作人</th>
					<th >日志类型</th>
					<th >操作时间</th>
					<th >内容</th>
					<th >操作耗时(ms)</th>
					<th >操作方法</th>
				</tr>
			</tbody>

			<c:forEach var="consoleLog" items="${page.list}">

				<tr onclick="showConsoleLogDetail(${consoleLog.id})" title="单击查看详情" id="consoleLog${consoleLog.id}">
					<td align="center" onclick="changeCheck('id${consoleLog.id}')"><input type="checkbox" id="id${consoleLog.id}" name="ids" title="选择" value="${consoleLog.id}"></td>
					
					<td>${consoleLog.operatorId}</td>
					<td>${consoleLog.operatorName}</td>
					<td>${consoleLog.logType}</td>
					<td><fmt:formatDate value="${consoleLog.createdAt}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
					<td>${consoleLog.content}</td>
					<td>${consoleLog.operateTime}</td>
					<td>${consoleLog.operateMethod}</td>
					<td>
						<div class="col-sm-4" align="center">
							<button type="button" onclick="toConsoleLogModify('${consoleLog.id}')" class="btn btn-warning btn-flat btn-shorter">修改</button>
						</div>
						<div class="col-sm-4" align="center">
							<button type="button" onclick="delConsoleLogConfirm('${consoleLog.id}')" class="btn btn-danger btn-flat btn-shorter">删除</button>
						</div>						
					</td>
				</tr>

			</c:forEach>

		</table>
	</form>

</div>
<!-- /.box-body -->

<div class="box-footer clearfix">

	<ct:paging pageNo="${page.pageNo}" recordCount="${page.recordCount}" pageSize="${page.pageSize}" url="/consoleLog/list" />

</div>


<!-- Modal -->
<div class="modal fade " id="editConsoleLogModal" role="dialog" aria-labelledby="editConsoleLogModalLabel" data-backdrop="false">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="closeModal('editConsoleLogModal')">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="editConsoleLogModalLabel">新增</h4>
			</div>
			<div class="modal-body" id="editConsoleLogModalBody">
				<form class="form-horizontal" id="editConsoleLogForm">
					<input type="hidden" id="id" name="id">
					<div class="box-body">
						<div class="form-group ">
							<label for="operatorId" class="col-sm-2 control-label">操作人id</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="operatorId" name="operatorId" placeholder="操作人id" >
							</div>
						</div>
						<div class="form-group ">
							<label for="operatorName" class="col-sm-2 control-label">操作人</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="operatorName" name="operatorName" placeholder="操作人" >
							</div>
						</div>
						<div class="form-group ">
							<label for="logType" class="col-sm-2 control-label">日志类型</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="logType" name="logType" placeholder="日志类型" >
							</div>
						</div>
						<div class="form-group ">
							<label for="createdAt" class="col-sm-2 control-label">操作时间</label>
							<div class="col-sm-10">
								<input type="text" class="form-control datetimepicker" id="createdAt" name="createdAt" placeholder="操作时间" required>
							</div>
						</div>
						<div class="form-group ">
							<label for="content" class="col-sm-2 control-label">内容</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="content" name="content" placeholder="内容" >
							</div>
						</div>
						<div class="form-group ">
							<label for="operateTime" class="col-sm-2 control-label">操作耗时(ms)</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="operateTime" name="operateTime" placeholder="操作耗时(ms)" >
							</div>
						</div>
						<div class="form-group ">
							<label for="operateMethod" class="col-sm-2 control-label">操作方法</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="operateMethod" name="operateMethod" placeholder="操作方法" >
							</div>
						</div>
					</div>
					<!-- /.box-body -->
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default " data-dismiss="modal" onclick="closeModal('editConsoleLogModal')">关闭</button>
				<button type="button" class="btn btn-primary" onclick="saveConsoleLogAdd()" id="editSaveConsoleLogBtn">保存</button>
			</div>

		</div>
	</div>
</div>
